package com.ruoyi.basedata.service.impl;

import java.util.Arrays;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.basedata.mapper.BillArrearsMapper;
import com.ruoyi.basedata.domain.BillArrears;
import com.ruoyi.basedata.service.IBillArrearsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
/**
 * 欠费明细Service业务层处理
 * 
 * @author gdqt
 * @date 2025-04-23
 */
@Service
public class BillArrearsServiceImpl extends ServiceImpl<BillArrearsMapper, BillArrears> implements IBillArrearsService
{
    @Autowired
    private BillArrearsMapper billArrearsMapper;

    /**
     * 查询欠费明细
     * 
     * @param id 欠费明细主键
     * @return 欠费明细
     */
    @Override
    public BillArrears selectBillArrearsById(Long id)
    {

        return billArrearsMapper.selectById(id);
    }

    /**
     * 查询欠费明细列表
     * 
     * @param billArrears 欠费明细
     * @return 欠费明细
     */
    @Override
    public List<BillArrears> selectBillArrearsList(BillArrears billArrears)
    {
        LambdaQueryWrapper<BillArrears> queryWrapper = new LambdaQueryWrapper<>();
        if(!StringUtils.isEmpty(billArrears.getEnergyUseClassification())){
            queryWrapper.eq(BillArrears::getEnergyUseClassification,billArrears.getEnergyUseClassification());
        }
        if(!StringUtils.isEmpty(billArrears.getUserId())){
            queryWrapper.eq(BillArrears::getUserId,billArrears.getUserId());
        }
        if(!StringUtils.isEmpty(billArrears.getTerminalId())){
            queryWrapper.eq(BillArrears::getTerminalId,billArrears.getTerminalId());
        }
        if(billArrears.getStartReading() != null){
            queryWrapper.eq(BillArrears::getStartReading,billArrears.getStartReading());
        }
        if(billArrears.getEndReading() != null){
            queryWrapper.eq(BillArrears::getEndReading,billArrears.getEndReading());
        }
        if(billArrears.getTotalVal() != null){
            queryWrapper.eq(BillArrears::getTotalVal,billArrears.getTotalVal());
        }
        if(billArrears.getUnitPrice() != null){
            queryWrapper.eq(BillArrears::getUnitPrice,billArrears.getUnitPrice());
        }
        if(billArrears.getLateFee() != null){
            queryWrapper.eq(BillArrears::getLateFee,billArrears.getLateFee());
        }
        if(billArrears.getReadDate() != null){
            queryWrapper.eq(BillArrears::getReadDate,billArrears.getReadDate());
        }
        if(billArrears.getStatus() != null){
            queryWrapper.eq(BillArrears::getStatus,billArrears.getStatus());
        }
        return billArrearsMapper.selectList(queryWrapper);
    }

    /**
     * 新增欠费明细
     * 
     * @param billArrears 欠费明细
     * @return 结果
     */
    @Override
    public int insertBillArrears(BillArrears billArrears)
    {
        return billArrearsMapper.insert(billArrears);
    }

    /**
     * 修改欠费明细
     * 
     * @param billArrears 欠费明细
     * @return 结果
     */
    @Override
    public int updateBillArrears(BillArrears billArrears)
    {
        billArrears.setUpdateTime(DateUtils.getNowDate());
        return billArrearsMapper.updateById(billArrears);
    }

    /**
     * 批量删除欠费明细
     * 
     * @param ids 需要删除的欠费明细主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteBillArrearsByIds(Long[] ids)
    {
        return billArrearsMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除欠费明细信息
     * 
     * @param id 欠费明细主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteBillArrearsById(Long id)
    {
        return billArrearsMapper.deleteById(id);
    }
}
